package com.shoujifeng.snowmusic.player;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.shoujifeng.snowmusic.player.http.ServerAccess;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;

public class SetStopTimeActivity extends Activity{
	private Button set_out_Btn_one;   //10分钟
	private Button set_out_Btn_two;   //20分钟
	private Button set_out_Btn_three; //30分钟
	private Button set_out_Btn_six;   //60分钟
	private Button set_out_Btn_nine;  //90分钟
	private Button set_out_Btn_out;   //120分钟
	@Override
	public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.set_stop_time);
		init();
	}
	private void init(){
		set_out_Btn_one = (Button) findViewById(R.id.set_out_Btn_one);
		set_out_Btn_two = (Button) findViewById(R.id.set_out_Btn_two);
		set_out_Btn_three = (Button) findViewById(R.id.set_out_Btn_three);
		set_out_Btn_six = (Button) findViewById(R.id.set_out_Btn_six);
		set_out_Btn_nine = (Button) findViewById(R.id.set_out_Btn_nine);
		set_out_Btn_out = (Button) findViewById(R.id.set_out_Btn_out);
		
		set_out_Btn_one.setOnClickListener(onClickListener);
		set_out_Btn_two.setOnClickListener(onClickListener);
		set_out_Btn_three.setOnClickListener(onClickListener);
		set_out_Btn_six.setOnClickListener(onClickListener);
		set_out_Btn_nine.setOnClickListener(onClickListener);
		set_out_Btn_out.setOnClickListener(onClickListener);
	}
	
	private View.OnClickListener onClickListener = new View.OnClickListener() {
		
		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			switch (arg0.getId()) {
			case R.id.set_out_Btn_one:
			{			
				  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");  
				  String nowTime = formatter.format(new Date());
				  
				  SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(SetStopTimeActivity.this);
			      Editor edit = spf.edit();
			      edit.putString(ServerAccess.SET_STOP_TIME, "10");
			      edit.putString(ServerAccess.SET_TIME, nowTime);
			      edit.commit();
			      Toast.makeText(SetStopTimeActivity.this, "播放器10分钟后停止!", Toast.LENGTH_SHORT)
					.show();
			      finish();
			}
				break;
			case R.id.set_out_Btn_two:
			{
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");  
				  String nowTime = formatter.format(new Date());
				SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(SetStopTimeActivity.this);
			      Editor edit = spf.edit();
			      edit.putString(ServerAccess.SET_STOP_TIME, "20");
			      edit.putString(ServerAccess.SET_TIME, nowTime);
			      edit.commit();
			      Toast.makeText(SetStopTimeActivity.this, "播放器20分钟后停止!", Toast.LENGTH_SHORT).show();
			      finish();
			}
				break;
			case R.id.set_out_Btn_three:
			{
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");  
				  String nowTime = formatter.format(new Date());
				SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(SetStopTimeActivity.this);
			      Editor edit = spf.edit();
			      edit.putString(ServerAccess.SET_STOP_TIME, "30");
			      edit.putString(ServerAccess.SET_TIME, nowTime);
			      edit.commit();
			      Toast.makeText(SetStopTimeActivity.this, "播放器30分钟后停止!", Toast.LENGTH_SHORT).show();
			      finish();
			}
				break;
			case R.id.set_out_Btn_six:
			{
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");  
				  String nowTime = formatter.format(new Date());
				SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(SetStopTimeActivity.this);
			      Editor edit = spf.edit();
			      edit.putString(ServerAccess.SET_STOP_TIME, "60");
			      edit.putString(ServerAccess.SET_TIME, nowTime);
			      edit.commit();
			      Toast.makeText(SetStopTimeActivity.this, "播放器60分钟后停止!", Toast.LENGTH_SHORT).show();
			      finish();
			}
				break;
			case R.id.set_out_Btn_nine:
			{
				  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");  
				  String nowTime = formatter.format(new Date());
				  SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(SetStopTimeActivity.this);
			      Editor edit = spf.edit();
			      edit.putString(ServerAccess.SET_STOP_TIME, "90");
			      edit.putString(ServerAccess.SET_TIME, nowTime);
			      edit.commit();
			      Toast.makeText(SetStopTimeActivity.this, "播放器90分钟后停止!", Toast.LENGTH_SHORT).show();
			      finish();
			}
				break;
			case R.id.set_out_Btn_out:
			{
				  SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(SetStopTimeActivity.this);
			      Editor edit = spf.edit();
			      edit.putString(ServerAccess.SET_STOP_TIME, "");
			      edit.putString(ServerAccess.SET_TIME, "");
			      edit.commit();
			      Toast.makeText(SetStopTimeActivity.this, "取消定时!", Toast.LENGTH_SHORT).show();
			      finish();
			}
				break;

			default:
				break;
			}
		}
	};
}
